package common

import (
	"context"
	"github.com/go-redis/redis/v8"
	"log"
	"time"
)

//定义一个全局的rdb
var (
	rdb *redis.Client
)

func init() {
	rdb = redis.NewClient(
		&redis.Options{
			Addr:     "127.0.0.1:6379",
			Password: "",
			DB:       0,   //use default db
			PoolSize: 100, //连接池大小
		},
	)
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	//测试连接rdb客户端
	_, err := rdb.Ping(ctx).Result()
	if err != nil {
		log.Printf("ping rdb fail, msg:%v", err,
		)
	}

}

func GetRedisDB() *redis.Client {
	return rdb
}
